<template>
  <view>
    <text class="component-title">子组件B</text>
    <view class="value-card">
      <text class="value-label">CompA组件传进来的值:</text>
      <text class="value-content" :class="{ 'text-blue': result }">{{ result || '暂无' }}</text>
    </view>
    <view class="input-row">
      <text class="value-label">回传值:</text>
      <input 
        v-model="callbackValue" 
        class="input-yellow" 
        placeholder="请输入回传值" 
        placeholder-style="color: #999;"
      />
      <button class="btn-warn" @click="sendOutside">回传</button>
    </view>
  </view>
</template>

<script>
export default {
  data() {
    return { result: '', callbackValue: '' };
  },
  created() {
    uni.$on('getIntent', (msg) => {
      this.result = msg;
    });
  },
  destroyed() {
    uni.$off('getIntent');
  },
  methods: {
    sendOutside() {
      this.$emit('callBackFun', this.callbackValue);
    }
  }
}
</script>

<style scoped>
.component-title {
  font-size: 36rpx;
  font-weight: bold;
  color: #333;
  display: block;
  margin-bottom: 20rpx;
}
.value-card {
  background: #f5f5f5;
  border-radius: 8rpx;
  padding: 20rpx;
  margin-bottom: 20rpx;
}
.value-label {
  font-size: 28rpx;
  color: #333;
  display: block;
  margin-bottom: 10rpx;
}
.value-content {
  font-size: 30rpx;
  color: #666;
}
.text-blue {
  color: #007AFF;
  font-weight: bold;
}
.input-row {
  display: flex;
  align-items: center;
  gap: 10rpx;
}
.input-yellow {
  flex: 1;
  height: 80rpx;
  border: 1px solid #eee;
  border-radius: 8rpx;
  padding: 0 20rpx;
  font-size: 28rpx;
  background: #333;
  color: yellow;
}
.btn-warn {
  background: #FF3B30;
  color: #fff;
  height: 80rpx;
  line-height: 80rpx;
  border-radius: 8rpx;
  font-size: 28rpx;
  width: 80rpx;
}
</style>